package com.base.controller;


import com.base.entity.bo.SciencePersonBo;
import com.base.entity.bo.UserEntity;
import com.base.entity.vo.SciencePersonVo;
import com.base.service.SciencePersonService;
import com.base.utils.CutPageBean;
import com.base.utils.Result;
import com.common.core.domain.AjaxResult;
import com.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Api(tags = "科研人员")
@RestController
@RequestMapping("/kyry")
public class SciencePersonController {
    @Autowired
    SciencePersonService sciencePersonService;

    @PostMapping("/getPersonList")
    @ApiOperation(value = "查询科研人员列表")
    public Result getPersonList(@RequestBody SciencePersonVo sciencePersonVo){
        CutPageBean<SciencePersonBo> cutPageBean =sciencePersonService.getPersonList(sciencePersonVo);
        return Result.succ(cutPageBean);
    }

    @PostMapping("/deletPersonList")
    @ApiOperation(value = "删除科研人员")
    public Result deletPersonList(@RequestBody SciencePersonBo sciencePersonBo){
        int row=sciencePersonService.deletPersonList(sciencePersonBo);
        if (row > 0) {
            return Result.succ("删除成功");
        } else {
            return Result.fail("删除失败");
        }
    }

    @PostMapping("/insertPersonList")
    @ApiOperation(value = "新增科研人员")
    public AjaxResult insertPersonList(@RequestBody SciencePersonBo sciencePersonBo){
        AjaxResult row=sciencePersonService.insertPersonList(sciencePersonBo);
        return row;
    }

    @PostMapping("/updatePersonList")
    @ApiOperation(value = "编辑科研人员")
    public AjaxResult updatePersonList(@RequestBody SciencePersonBo sciencePersonBo){
        AjaxResult row=sciencePersonService.updatePersonList(sciencePersonBo);
        return row;
    }

    @PostMapping("/personDetails")
    @ApiOperation(value = "查询科研人员详情")
    public Result personDetails(@RequestBody SciencePersonVo sciencePersonVo){
        List<SciencePersonBo> list =sciencePersonService.personDetails(sciencePersonVo);
        return Result.succ(list);
    }

    @PostMapping("/personDetailsView")
    @ApiOperation(value = "查看科研人员详情")
    public Result personDetailsView(@RequestBody SciencePersonVo sciencePersonVo){
        List<SciencePersonBo> list =sciencePersonService.personDetailsView(sciencePersonVo);
        return Result.succ(list);
    }

    @PostMapping("/processPerson")
    @ApiOperation(value = "审核科研人员")
    public AjaxResult processPerson(@RequestBody SciencePersonBo sciencePersonBo){
        AjaxResult row=sciencePersonService.updatePersonList(sciencePersonBo);
        return  row;
    }

    @PostMapping("/processCount")
    @ApiOperation(value = "科研人员条数")
    public Result processCount(@RequestBody SciencePersonVo sciencePersonVo){
        ArrayList<Map<String,String>> list=sciencePersonService.processCount(sciencePersonVo);
        return Result.succ(list);
    }

    @GetMapping ("/officeContact")
    @ApiOperation(value = "办事联络列表")
    public Result officeContact(){
        List<UserEntity> list=sciencePersonService.officeContact();
        return Result.succ(list);
    }


    @ApiOperation("导出科研人员列表")
    @PostMapping("/exportList")
    public void exportList(HttpServletResponse response, @RequestBody SciencePersonVo sciencePersonVo) {
        List<SciencePersonBo> list =sciencePersonService.exportList(sciencePersonVo);
        ExcelUtil<SciencePersonBo> util = new ExcelUtil<>(SciencePersonBo.class);
        util.exportExcel(response, list, "科研人员列表","科研人员列表");
    }
}
